package com.frogs.ucenter.v1.request;

import javax.servlet.http.HttpServletRequest;

import com.frogs.framework.util.StringUtil;
import com.frogs.framework.web.HttpRequestInfo;
import com.frogs.system.util.ApiUrlParamEnum;
import com.frogs.system.util.SmsPartnerEnum;
import com.frogs.system.web.api.request.Request;
import com.frogs.system.web.exception.RequestIllegalException;

public class SmsReceiveRequest extends Request {
	
	/**
	 * 发送号码，多个号码用","分开，群发号码不能超过100个
	 */
	private String phoneNumber;
	/**
	 * 发送的消息
	 */
	private String messageContent;
	/**
	 * 是否提供状态报告
	 * 0：不提供，1：提供
	 */
	private int isReport;
	/**
	 * 发送的级别(初期单发为5-8级, 群发为2-4级, 手机验证码为9级)
	 */
	private int sendLevel;
	
	/**
	 * 短信合作方
	 */
	private String partner;
	
	public String getPhoneNumber() {
		return phoneNumber;
	}
	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}
	public String getMessageContent() {
		return messageContent;
	}
	public void setMessageContent(String messageContent) {
		this.messageContent = messageContent;
	}
	public int getIsReport() {
		return isReport;
	}
	public void setIsReport(int isReport) {
		this.isReport = isReport;
	}
	public int getSendLevel() {
		return sendLevel;
	}
	public void setSendLevel(int sendLevel) {
		this.sendLevel = sendLevel;
	}
	
	public String getPartner() {
		return partner;
	}
	public void setPartner(String partner) {
		this.partner = partner;
	}
	/** */
	public SmsReceiveRequest() {
	}
	
	@Override
	public void parse(HttpServletRequest request) {
		HttpRequestInfo requestInfo = new HttpRequestInfo(request);
		
	
		this.phoneNumber = requestInfo.getParameter(ApiUrlParamEnum.phoneNumber.getParamName());
		this.messageContent = requestInfo.getParameter(ApiUrlParamEnum.messageContent.getParamName());
		this.isReport = requestInfo.getIntParameter(ApiUrlParamEnum.isReport.getParamName(),0);
		this.sendLevel = requestInfo.getIntParameter(ApiUrlParamEnum.sendLevel.getParamName(),1);
		this.partner = requestInfo.getParameter(ApiUrlParamEnum.partner.getParamName(), SmsPartnerEnum.LAN_CHUANG.getCode());
		if ( StringUtil.isEmpty(phoneNumber) ) {
			throw new RequestIllegalException("error phoneNumber: " + phoneNumber);
		}
		if ( StringUtil.isEmpty(messageContent) ) {
			throw new RequestIllegalException("error messageContent: " + messageContent);
		}
		if ( sendLevel<=0||sendLevel>9 ) {
			throw new RequestIllegalException("error sendLevel: " + sendLevel);
		}
		/*发送的长度不能大于500*/
		if ( messageContent.length()>500 ) {
			throw new RequestIllegalException("error too long messageContent: " + messageContent);
		}
	}
}
